import { ref, reactive } from 'vue';
import { getTableData as QueryList } from '@/api/userManage/userManage';
import type { SeachData, TableListItem } from '@/api/userManage/userManage.d';

export default function useTableData(searchForm: SeachData) {
    const common = {
        ellipsis: true,
        tooltip: true,
    }
    const columns = ref([
        {
            title: '序号',
            dataIndex: 'index',
            // width: 70,
            slotName: 'index',
            ...common
        },
        {
            title: '用户名称',
            // width: 180,
            dataIndex: 'userName',
            ...common
        },
        {
            title: '手机号',
            // width: 220,
            dataIndex: 'mobile',
            ...common
        },
        {
            title: '密码验证码',
            // width: 184,
            dataIndex: 'shortCode',
            ...common
        },
        {
            title: '标注单位',
            // width: 200,
            dataIndex: 'company',
            slotName: 'company',
            ...common
        },
        {
            title: '角色',
            // width: 200,
            dataIndex: 'roles',
            slotName: 'roles',
            ...common
        },
        {
            title: '用户状态',
            // width: 90,
            dataIndex: 'action',
            slotName: 'action',
            ...common
        },
        {
            title: '操作',
            // width: 90,
            dataIndex: 'operate',
            slotName: 'operate',
            ...common
        },
    ]);

    const scroll = reactive({
        x: '80%',
        y: 'calc(100% - 50px)',
        // maxHeight: 540
    })
    
    let data = ref<TableListItem[]>([]);
    let total = ref<number>(0);
  
    const getTableData = async () => {
        let params = { ...searchForm };
        const res = await QueryList(params);
        res && (data.value = res.data.list);
        res && (total.value = res.data.total);
    }

    return {
        columns,
        data,
        scroll,
        total,
        getTableData
    }
}